#ifndef MODERNUI_H
#define MODERNUI_H

#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFrame>
#include <QPainter>
#include <QPropertyAnimation>
#include <QGraphicsDropShadowEffect>
#include <QMouseEvent>
#include <QTimer>
#include <QPoint>
#include <QColor>
#include <QSize>
#include <QPaintEvent>
#include <QWheelEvent>
#include <QEvent>
#include <QEnterEvent>
#include <QGridLayout>
#include <QDate>

// Modern Card Widget - 现代化卡片组件
class ModernCard : public QFrame
{
    Q_OBJECT
    Q_PROPERTY(qreal elevation READ elevation WRITE setElevation)

public:
    explicit ModernCard(QWidget *parent = nullptr);
    explicit ModernCard(const QString& title, const QString& subtitle = "", QWidget *parent = nullptr);
    
    void setTitle(const QString& title);
    void setSubtitle(const QString& subtitle);
    void setContentWidget(QWidget* widget);
    
    qreal elevation() const { return m_elevation; }
    void setElevation(qreal elevation);
    
protected:
    void paintEvent(QPaintEvent *event) override;
    void enterEvent(QEnterEvent *event) override;
    void leaveEvent(QEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

private:
    void setupUI();
    void updateShadow();
    
    QVBoxLayout* m_layout;
    QLabel* m_titleLabel;
    QLabel* m_subtitleLabel;
    QWidget* m_contentWidget;
    QVBoxLayout* m_contentLayout;
    
    qreal m_elevation;
    QPropertyAnimation* m_elevationAnimation;
    QGraphicsDropShadowEffect* m_shadowEffect;
    bool m_pressed;
};

// Modern Button Widget - 现代化按钮组件
class ModernButton : public QPushButton
{
    Q_OBJECT
    Q_PROPERTY(qreal elevation READ elevation WRITE setElevation)
    Q_PROPERTY(QColor rippleColor READ rippleColor WRITE setRippleColor)

public:
    enum ButtonStyle {
        Filled,     // 填充按钮
        Outlined,   // 轮廓按钮
        Text,       // 文本按钮
        Floating    // 浮动按钮
    };

    explicit ModernButton(QWidget *parent = nullptr);
    explicit ModernButton(const QString& text, QWidget *parent = nullptr);
    explicit ModernButton(const QString& text, ButtonStyle style, QWidget *parent = nullptr);
    
    ButtonStyle buttonStyle() const { return m_style; }
    void setButtonStyle(ButtonStyle style);
    
    qreal elevation() const { return m_elevation; }
    void setElevation(qreal elevation);
    
    QColor rippleColor() const { return m_rippleColor; }
    void setRippleColor(const QColor& color);
    
protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void enterEvent(QEnterEvent *event) override;
    void leaveEvent(QEvent *event) override;

private slots:
    void updateRipple();

private:
    void setupAnimations();
    void startRippleAnimation(const QPoint& center);
    void updateShadow();
    
    ButtonStyle m_style;
    qreal m_elevation;
    QColor m_rippleColor;
    
    // Ripple effect
    QPropertyAnimation* m_rippleAnimation;
    QTimer* m_rippleTimer;
    QPoint m_rippleCenter;
    qreal m_rippleRadius;
    qreal m_rippleOpacity;
    
    // Elevation animation
    QPropertyAnimation* m_elevationAnimation;
    QGraphicsDropShadowEffect* m_shadowEffect;
    
    // Hover animation
    QPropertyAnimation* m_hoverAnimation;
    qreal m_hoverProgress;
};

// Floating Preview Widget - 浮动预览组件
class FloatingPreview : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(qreal scale READ scale WRITE setScale)

public:
    explicit FloatingPreview(QWidget *parent = nullptr);
    
    void setPreviewImage(const QImage& image);
    void setSettings(const class OutputSettings& settings);
    
    qreal scale() const { return m_scale; }
    void setScale(qreal scale);

public slots:
    void showPreview();
    void hidePreview();
    void updatePreview();

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void wheelEvent(QWheelEvent *event) override;

private:
    void setupAnimations();
    void renderPreviewPage();
    
    QImage m_previewImage;
    QImage m_renderedPreview;
    class OutputSettings* m_settings;
    
    qreal m_scale;
    QPoint m_offset;
    bool m_dragging;
    QPoint m_lastDragPos;
    
    QPropertyAnimation* m_scaleAnimation;
    QPropertyAnimation* m_fadeAnimation;
    QGraphicsOpacityEffect* m_opacityEffect;
};

// Modern Slider Widget - 现代化滑块组件
class ModernSlider : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(qreal value READ value WRITE setValue)

public:
    explicit ModernSlider(Qt::Orientation orientation = Qt::Horizontal, QWidget *parent = nullptr);
    
    qreal value() const { return m_value; }
    void setValue(qreal value);
    
    qreal minimum() const { return m_minimum; }
    void setMinimum(qreal minimum);
    
    qreal maximum() const { return m_maximum; }
    void setMaximum(qreal maximum);
    
    void setRange(qreal minimum, qreal maximum);
    
    QString suffix() const { return m_suffix; }
    void setSuffix(const QString& suffix);

signals:
    void valueChanged(qreal value);

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void wheelEvent(QWheelEvent *event) override;
    QSize sizeHint() const override;

private:
    void updateValueFromPosition(const QPoint& pos);
    QRect getSliderRect() const;
    QRect getHandleRect() const;
    
    Qt::Orientation m_orientation;
    qreal m_value;
    qreal m_minimum;
    qreal m_maximum;
    QString m_suffix;
    
    bool m_dragging;
    QPropertyAnimation* m_hoverAnimation;
    qreal m_hoverProgress;
};

#endif // MODERNUI_H
